package org.jivesoftware.smack;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.RosterPacket;
import org.jivesoftware.smack.packet.RosterPacket.Item;
import org.jivesoftware.smack.packet.RosterPacket.ItemStatus;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;

public class RosterEntry
{
  private final Connection connection;
  private String name;
  private final Roster roster;
  private RosterPacket.ItemStatus status;
  private RosterPacket.ItemType type;
  private String user;

  RosterEntry(String paramString1, String paramString2, RosterPacket.ItemType paramItemType, RosterPacket.ItemStatus paramItemStatus, Roster paramRoster, Connection paramConnection)
  {
    this.user = paramString1;
    this.name = paramString2;
    this.type = paramItemType;
    this.status = paramItemStatus;
    this.roster = paramRoster;
    this.connection = paramConnection;
  }

  static RosterPacket.Item toRosterItem(RosterEntry paramRosterEntry)
  {
    RosterPacket.Item localItem = new RosterPacket.Item(paramRosterEntry.getUser(), paramRosterEntry.getName());
    localItem.setItemType(paramRosterEntry.getType());
    localItem.setItemStatus(paramRosterEntry.getStatus());
    Iterator localIterator = paramRosterEntry.getGroups().iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
        return localItem;
      localItem.addGroupName(((RosterGroup)localIterator.next()).getName());
    }
  }

  public boolean equals(Object paramObject)
  {
    boolean bool;
    if (this == paramObject)
      bool = true;
    while (true)
    {
      while (true)
      {
        return bool;
        if ((paramObject == null) || (!(paramObject instanceof RosterEntry)))
          break;
        bool = this.user.equals(((RosterEntry)paramObject).getUser());
      }
      bool = false;
    }
  }

  public Collection<RosterGroup> getGroups()
  {
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = this.roster.getGroups().iterator();
    while (true)
    {
      RosterGroup localRosterGroup;
      do
      {
        if (!(localIterator.hasNext()))
          return Collections.unmodifiableCollection(localArrayList);
        localRosterGroup = (RosterGroup)localIterator.next();
      }
      while (!(localRosterGroup.contains(this)));
      localArrayList.add(localRosterGroup);
    }
  }

  public String getName()
  {
    return this.name;
  }

  public RosterPacket.ItemStatus getStatus()
  {
    return this.status;
  }

  public RosterPacket.ItemType getType()
  {
    return this.type;
  }

  public String getUser()
  {
    return this.user;
  }

  public void setName(String paramString)
  {
    if ((paramString != null) && (paramString.equals(this.name)));
    while (true)
    {
      return;
      this.name = paramString;
      RosterPacket localRosterPacket = new RosterPacket();
      localRosterPacket.setType(IQ.Type.SET);
      localRosterPacket.addRosterItem(toRosterItem(this));
      this.connection.sendPacket(localRosterPacket);
    }
  }

  public String toString()
  {
    Iterator localIterator;
    StringBuilder localStringBuilder = new StringBuilder();
    if (this.name != null)
      localStringBuilder.append(this.name).append(": ");
    localStringBuilder.append(this.user);
    Collection localCollection = getGroups();
    if (!(localCollection.isEmpty()))
    {
      localStringBuilder.append(" [");
      localIterator = localCollection.iterator();
      localStringBuilder.append(((RosterGroup)localIterator.next()).getName());
    }
    while (true)
    {
      if (!(localIterator.hasNext()))
      {
        localStringBuilder.append("]");
        return localStringBuilder.toString();
      }
      localStringBuilder.append(", ");
      localStringBuilder.append(((RosterGroup)localIterator.next()).getName());
    }
  }

  void updateState(String paramString, RosterPacket.ItemType paramItemType, RosterPacket.ItemStatus paramItemStatus)
  {
    this.name = paramString;
    this.type = paramItemType;
    this.status = paramItemStatus;
  }
}